package com.dhms.vostok1.data.spot_patrol

import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.squareup.moshi.Json
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.ObjectId
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject

class SpotCheckItems : RealmObject {
    var temperature: Boolean? = false
    var vibration: Boolean? = false
}

class SpotCheckItem : RealmObject {
    var temperature: Float? = null
    var acceleration: Float? = null
    var speed: Float? = null
}

class SpotCheckFCCItem : RealmObject {
    var temperature: String? = null
    var acceleration: String? = null
    var speed: String? = null
}

class SpotDetectorData : RealmObject {
    @Json(name = "check_spot")
    var checkSpot: String? = null

    @Json(name = "spot_id")
    var spotId: Long? = null

    @Json(name = "spot_rpm")
    var spotRPM: Long? = 1480

    @Json(name = "check_items")
    var checkItems: SpotCheckItems? = null
    var threshold: SpotCheckItem? = null
    var result: SpotCheckItem? = null
    var fcc: SpotCheckFCCItem? = null

    @Json(name = "vib_oss")
    var vibFileOss: String? = null
    var vibData: RealmList<Float> = realmListOf()
    var terminalInfoData: String? = null
    var blockData: String? = null
    var tsData: String? = null

    @Json(name = "is_abnormal")
    var isAbnormal: Boolean? = false
}

class TerminalInfo(
    @Json(name = "terminal_id")
    var terminalSn: Int,
    @Json(name = "model")
    var model: String,
    @Json(name = "hw_version")
    var hwVersion: String? = null,
    @Json(name = "attribute")
    var attribute: Float? = 0f,
    @Json(name = "hw_version_num")
    var hwVersionNum: Int? = null,
    @Json(name = "num_net_interface")
    var numNetInterface: Int = 0,
    /*  the main network interface MAC address */
    @Json(name = "mac_addr")
    var macAddr: String,
    /*  array of software images version, map[swfcc] = version ?? */
    @Json(name = "sw_versions")
    var swVersions: Map<String, Int?>?,
    @Json(name = "other_mac_addr")
    var otherMacAddr: List<String>? = null,
    /*  FOURCC */
    @Json(name = "sw_fourcc")
    var swFourcc: List<String>? = null,
    @Json(name = "sw_fourcc_versions")
    var swFourccVersions: List<Int>? = null
)

data class CollectParam(
    @Json(name = "sample_rate")
    var sampleRate: Int,
    @Json(name = "samples")
    var samples: Int,
    @Json(name = "collect_interval")
    var collectInterval: Int,
    @Json(name = "short_upload_interval")
    var shortUploadInterval: Int,
    @Json(name = "long_upload_interval")
    var longUploadInterval: Int
)

data class TerminalFeature(
    /*  采集参数 */
    @Json(name = "collects")
    var collects: List<String>,
    /*  map[string]float */
    @Json(name = "uploads")
    var uploads: Any? = null,
    /*  map[string]float */
    @Json(name = "other_params")
    var otherParams: Any? = null
)

data class TerminalExtraInfo(
    @Json(name = "collection_point_id")
    var cpId: Long?,
    var type: String = "spot"
)

class ReportTerminalTask : RealmObject {
    var id: ObjectId = ObjectId.create()
    var terminalInfoStr: String? = null
}

// 点检仪信息
data class ReportTerminalInfo(
    @Json(name = "remote_id")
    var remoteSn: Int? = null,
    @Json(name = "terminal_id")
    var terminalSn: Int,
    @Json(name = "timestamp")
    var timestamp: Int,
    @Json(name = "extra_info")
    var extraInfo: String,
    @Json(name = "info")
    var info: TerminalInfo?,
    @Json(name = "param")
    var param: CollectParam? = null,
    @Json(name = "feature")
    var feature: TerminalFeature?
)

// 点检仪采集参数信息
data class ReportTsData(
    @Json(name = "timestamp")
    var timestamp: Int,
    @Json(name = "extra_info")
    var extraInfo: String,
    @Json(name = "uploads")
    var uploads: List<Map<String, Float?>>?,
    @Json(name = "remote_id")
    var remoteSn: Int? = null,
    @Json(name = "terminal_id")
    var terminalSn: Int
)

// 点检仪振动数据
data class ReportBlockData(
    @Json(name = "timestamp")
    var timestamp: Int,
    @Json(name = "extra_info")
    var extraInfo: String,
    /*  fourcc */
    @Json(name = "collect")
    var collect: String,
    /*  base64 encode */
    @Json(name = "data")
    var data: String,
    @Json(name = "remote_id")
    var remoteSn: Int? = null,
    @Json(name = "terminal_id")
    var terminalSn: Int? = null
)

data class CheckInstrumentSpeedResData(
    @Json(name = "speed_rpm")
    var speedRPMInterval: String,
    @Json(name = "sampling_frequency")
    var sampleRate: Long,
    @Json(name = "sampling_points")
    var samples: Long,
)

@Entity(tableName = "check_instrument_speed")
data class CheckInstrumentSpeedData(
    @PrimaryKey
    @ColumnInfo(name = "speed_rpm_interval")
    @NonNull var speedRPMInterval: String,
    @NonNull var model: String,
    @ColumnInfo(name = "minimum_rpm")
    var minimumRPM: Long?,
    @ColumnInfo(name = "sample_rate")
    @NonNull var sampleRate: Long,
    @NonNull var samples: Long,
)

data class FirmwaresReqQuery(
    @Json(name = "page")
    var page: Long? = null,
    @Json(name = "per_page")
    var perPage: Long? = null,
    @Json(name = "model_category")
    var modelCategory: String? = null,
    @Json(name = "model_name")
    var modelName: String? = null,
    @Json(name = "model_primary_NO")
    var modelPrimaryNO: String? = null,
    @Json(name = "model_NO")
    var modelNO: String? = null,
    @Json(name = "publish_status")
    var publishStatus: Long? = null,
    @Json(name = "use_status")
    var useStatus: Long? = null,
    var sort: String? = null
)

data class FirmwareData(
    @Json(name = "model_id")
    var modelId: Long? = null,
    @Json(name = "type")
    var type: String? = null,
    @Json(name = "version")
    var version: String,
    @Json(name = "version_num")
    var versionNum: Int,
    @Json(name = "target_versions")
    var targetVersions: List<Long>? = null,
    @Json(name = "publish_task")
    var publishTask: String? = null,
    var firmware: Map<String, String>?,
    @Json(name = "md5")
    var md5: String? = null,
    @Json(name = "creater")
    var creator: String? = null,
    @Json(name = "description")
    var description: String? = null,
    @Json(name = "references")
    var references: String? = null,
    @Json(name = "publish_at")
    var publishAt: Long? = null,
    @Json(name = "publish_by")
    var publishBy: String? = null,
    @Json(name = "publish_status")
    var publishStatus: Any? = null,
    @Json(name = "use_status")
    var useStatus: Any? = null
)

data class CollectedData<T>(
    var terminalSn: String? = null,
    var time: Int? = null,
    var data: T
)
